﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace Scrumrun.Models
{

    public class Project : IValidatableObject
    {

        public Project()
        {
            this.UserStories = new HashSet<UserStory>();
            this.Sprints = new HashSet<Sprint>();
        }

        [Key]
        public int ProjectId { get; set; }

        [Required]
        [StringLength(300)]
        [Display(Name = "Project name")]
        public string Name { get; set; }

        [Required]
        [Display(Name = "Start date")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
        public DateTime StartDate { get; set; }

        [Required]
        [Display(Name = "End date")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
        public DateTime EndDate { get; set; }

        [Required]
        [Display(Name="Iteration days")]
        [Range(2,60)]
        public int NumOfIterationDay { get; set; }

        [Required]
        [Display(Name = "Working days only")]
        
        public bool WorkingDaysOnly { get; set; }

        public virtual ICollection<UserStory> UserStories { get; set; }
        public virtual ICollection<Sprint> Sprints { get; set; }



        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (EndDate <= StartDate || EndDate <= DateTime.Today)
            {
                yield return new ValidationResult("End date must be greater then start date and today's date.");
            }
        }


    }
}